package com.attempt.grab.config;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * @author xuhaifeng
 * @since 2022年02月25日 下午 1:15
 */
@Configuration
public class CoreConfig {
    private static final String ASYNCHRONOUS_CHANNEL_PROVIDER = "java.nio.channels.spi.AsynchronousChannelProvider";
    private static final String ENHANCE_ASYNCHRONOUS_CHANNEL_PROVIDER = "org.smartboot.aio.EnhanceAsynchronousChannelProvider";

    /**
     * 配置属性
     */
    @Bean
    public void propertyConfig() {
        System.setProperty(ASYNCHRONOUS_CHANNEL_PROVIDER, ENHANCE_ASYNCHRONOUS_CHANNEL_PROVIDER);
    }

    /**
     * 配置fastJson为默认json解析器
     *
     * @return HttpMessageConverters
     */
    @Bean
    public HttpMessageConverters fastJsonHttpMessageConverters() {
        return new HttpMessageConverters(new FastJsonHttpMessageConverter());
    }

    /**
     * Server endpoint exporter server endpoint exporter.
     *
     * @return the server endpoint exporter
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}
